package com.vitae.controller;

import com.vitae.entity.Resume;
import com.vitae.service.resumeService.ResumeService;
import com.vitae.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2018/5/16.
 */
@Controller
@RequestMapping("resume")
public class ResumeController extends BaseApi{
    @Autowired
    ResumeService resumeService;

    @GetMapping("/")
    public String index(ModelMap modelMap){
        modelMap.put("Title","基本信息");
        return "resume/index";
    }

    @PostMapping("findAllResume")
    @ResponseBody
    public String findAllResume(int pageNo){
       List<Resume> resumeList= resumeService.findAllPage(pageNo);
        return "";
    }

    @PostMapping("/{id}")
    @ResponseBody
    public Result findResumeById(@PathVariable int id){
        Result result;
        Resume resume = resumeService.getOne(id);
       if(resume==null){
          return error("信息错误");
       }
       return success(200,"success",resume);
    }

    @PostMapping("/findResumeByUserId")
    @ResponseBody
    public Result findResumeByUserId(@RequestParam("userId") int userId,@RequestParam("pageNo") int pageNo){
        Result result;
        List<Resume> resume = resumeService.findResumeByUserId(userId,pageNo);
        Integer count =resumeService.findResumeByUserIdCount(userId);
        if(resume==null || count ==0){
            return error("信息错误");
        }
        Map<String,Object> modelMap=new HashMap<>();
        modelMap.put("pagesNum",count);//总页数
        modelMap.put("pageNo",pageNo);//当前页
        modelMap.put("resume",resume);
        return success(200,"success",modelMap);
    }
}
